package org.mozhu.mboot.core.web.freemarker;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.servlet.resource.ResourceUrlProvider;

/**
 * 提供便利的function，在ftl文件中使用
 */
@ControllerAdvice
public class FreemarkerControllerAdvice {
    @Autowired
    ResourceUrlProvider resourceUrlProvider;

    @ModelAttribute("urls")
    public ResourceUrlProvider urls() {
        return this.resourceUrlProvider;
    }

    @ModelAttribute("datetimeFormat")
    public DateTimeFormatMethod dateFormatMethod() {
        return new DateTimeFormatMethod();
    }

    @ModelAttribute("hasFieldError")
    public FormHasFieldErrorMethod hasFieldError() {
        return new FormHasFieldErrorMethod();
    }

}
